var path = require('path');
var srcUrl = path.resolve(__dirname, './src/views');
var webpack = require('webpack');
var autoprefixer=require('autoprefixer');

module.exports = {
    entry: {
        index: srcUrl + '/index/index.js',
        goods: srcUrl + '/goods/index.js',
        search: srcUrl + '/goods/search.js',
        member: srcUrl + '/member/index.js',
        member_search: srcUrl + '/member/searchAgent.js',
        member_pro: srcUrl + '/member/profile.js',
        member_Llevel: srcUrl + '/member/LlevelIndex.js',
        member_proxy: srcUrl + '/member/proxyIndex.js',
        member_dProfile: srcUrl + '/member/dProfile.js',
        apply: srcUrl + '/apply/index.js',
        apply_agent: srcUrl + '/apply/applyAgent.js',
        cate: srcUrl + '/cate/index.js',
        cart: srcUrl + '/cart/index.js',
        shipping: srcUrl + '/shipping/index.js',
        shipping_add: srcUrl + '/shipping/add.js',
        order: srcUrl + '/order/index.js',
        order_list: srcUrl + '/order/list.js',
        order_detail: srcUrl + '/order/detail.js',
        order_review: srcUrl + '/order/review.js'
    },
    output: {
        path: path.resolve(__dirname, '../../public/static/home/js'),
        publicPath: '/static/home',
        filename: '[name].js'
    },
    module: {
        loaders: [{
            test: /\.js$/,
            loader: 'babel-loader',
            exclude: /node_modules/,
            query: {
                presets: ['es2015']
            }
        }, {
            test: /\.css$/,
            loader: 'style-loader!css-loader?importLoaders=1!postcss-loader',
        }, {
            test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/,
            loader: 'url-loader',
            query: {
                name: "[name].[ext]",
                limit: '8192'
            }
        }]
    },
    postcss: function () {
        return [require('autoprefixer')];
    },
    devtool: '#eval-source-map',
    devServer: {
        historyApiFallback: true,
        hot: true,
        inline: true,
        progress: true,
        port: 3000
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': '"development"',
            DEV: JSON.stringify(true)
        })
    ]

}

if (process.env.NODE_ENV === 'production') {

    module.exports.devtool = '#source-map';
    module.exports.plugins = [
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: '"production"'
            },
            DEV: JSON.stringify(false)

        }),
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            }
        })
    ]
}